package com.xyzq.cgate.common.enums;


import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Optional;

/**
 * @Description:
 * @author chenchen
 * @date 2019/5/30 15:28
 */
public enum SerializeEnum {

    /**
     * Jdk serialize protocol enum.
     */
    JDK("jdk"),

    /**
     * Kryo serialize protocol enum.
     */
    KRYO("kryo"),

    /**
     * Hessian serialize protocol enum.
     */
    HESSIAN("hessian"),

    /**
     * Fast json serialize enum.
     */
    FAST_JSON("fastJson"),

    /**
     * Protostuff serialize protocol enum.
     */
    PROTOSTUFF("protostuff");

    private String name;

    SerializeEnum(final String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public static SerializeEnum acquire(final String name) {
        return Optional.ofNullable(Arrays.stream(SerializeEnum.values())
                .filter(s -> StringUtils.equals(s.getName(), name))
                .findFirst())
                .get()
                .orElse(SerializeEnum.JDK);
    }
}
